#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

typedef int SLTDataType;

typedef struct SListNode
{
	SLTDataType data;
	struct SListNode* next;
}SLTNode;


SLTNode* BuySListNode(SLTDataType x)
{
	SLTNode* newnode = (SLTNode*)malloc(sizeof(SLTNode));
	if (newnode == NULL)
	{
		perror("malloc fail:::");
		exit(-1);
	}
	newnode->data = x;
	newnode->next = NULL;
	return newnode;
}


SLTNode* CreateSList(int n)
{
	SLTNode* phead = NULL;	
	SLTNode* ptail = NULL;
	for (int i = 0;i<n;i++)
	{
		SLTNode* newnode = BuySListNode(i);
		if (phead == NULL)
		{
			phead = ptail = newnode;
		}
		else
		{
			ptail->next = newnode;
			ptail = newnode;
		}
	}
}

void SLTPushFront(SLTNode** pphead, SLTDataType x)
{
	SLTNode* newnode = BuySListNode(x);
	newnode->next = *pphead;
	*pphead = newnode;
}




void SLTInsert(SLTNode** pphead, SLTNode* pos, SLTDataType x)
{
	assert(pos);
	if (*pphead == pos)
	{
		SListPushFront(pphead, x);
	}
	else
	{
		SLTNode* cur = *pphead;
		SLTNode* newnode = BuySListNode(x);
		while (cur)
		{
			if (cur->next == pos)
			{
				break;
			}
			cur = cur->next;
		}
		newnode->next = pos;
		cur->next = newnode;

	}
}


void SListPushBack(SLTNode** pplist, SLTDataType x)
{
	SLTNode* newnode = BuySListNode(x);
	SLTNode* ptail = *pplist;
	if (*pplist == NULL)
	{
		*pplist = newnode;
	}
	while (ptail->next)
	{
		ptail = ptail->next;
	}
	ptail->next = newnode;

}


void SListInsertAfter(SLTNode* pos, SLTDataType x)
{
	assert(pos);
	SLTNode* newnode = BuySListNode(x);
	SLTNode* prev = pos->next;
	pos->next = newnode;
	newnode->next = prev;
}


SLTNode* SListFind(SLTNode* plist, SLTDataType x)
{
	assert(plist);
	SLTNode* cur = plist;
	while (cur)
	{
		if (cur->data == x)
		{
			return cur;
		}
		cur = cur->next;
	}
	return NULL;
}


void SLTDestroy(SLTNode** pphead)
{
	SLTNode* ptail = *pphead;
	SLTNode* prev = NULL;
	while (ptail)
	{
		prev = ptail;
		ptail = ptail->next;
		free(prev);
	}
	*pphead = NULL;
}


int main()
{



	return 0;
}